<?php
class NhatuyendungsController extends AppController {

	var $name = 'Nhatuyendungs';
    var $components = array('RequestHandler','Redirect','Uploader.Uploader');
    //var $helpers = array('Html', 'Js','Form', 'DatePicker','Ajax','Javascript');
    
    
    
    function beforeFilter(){
        $this->Uploader->uploadDir = 'files\uploads\\'; //thu muc chua file upload
        $this->Uploader->enableUpload = true;
        $this->Uploader->maxFileSize = '2M'; // quy dinh dung luong duoc upload len toi da la 2 Megabytes
        $this->Uploader->maxNameLength = 25;//do dai cua ten file
        $this->Uploader->tempDir = TMP;
    }
	function index() {
		$this->Nhatuyendung->recursive = 0;
		$this->set('nhatuyendungs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid nhatuyendung', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('nhatuyendung', $this->Nhatuyendung->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Nhatuyendung->create();
			if ($this->Nhatuyendung->save($this->data)) {
				$this->Session->setFlash(__('The nhatuyendung has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The nhatuyendung could not be saved. Please, try again.', true));
			}
		}
	}
	function dangky($id = null) 
    {  
       	if (!empty($this->data))
        {
				
				$data = $this->Uploader->upload('fileName'); 
                $this->data['Nhatuyendung']['url'] = str_replace('\\','',str_replace('/','//',$data['path']));
                $this->Nhatuyendung->create();
               /* 
                $record = array();
                foreach($this->data['Nhatuyendung'] as $key =>$val)
                {
                    if($key!='fileName')
                    {
                        $record['Nhatuyendung'][$key]=$val;
                    }
                }
                */
    			if ($this->Nhatuyendung->save($this->data)) 
                {
                    
    				$this->Redirect->flashSuccess('Đăng thông tin tuyển dụng thành công', array('action' =>'index'));
                   
    			} 
                else 
                {
    				$this->Redirect->flashWarning('Không thể đăng thông tin tuyển dụng. Vui lòng thử lại');
    			}
		}
                 if (empty($this->data)) 
                {
	               $this->data = $this->Nhatuyendung->read(null, $id);
	            }
   }

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid nhatuyendung', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Nhatuyendung->save($this->data)) {
				$this->Session->setFlash(__('The nhatuyendung has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The nhatuyendung could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Nhatuyendung->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for nhatuyendung', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Nhatuyendung->delete($id)) {
			$this->Session->setFlash(__('Nhatuyendung deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Nhatuyendung was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
    
}

